package com.house.smallbug.house;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.house.smallbug.MainActivity;
import com.house.smallbug.R;


/**
 * @author 童旭
 */
public class HosueFragment extends Fragment implements View.OnClickListener{
    private MainActivity activity;
    private View layoutView;
    private TextView tvTitle,tvRight;
    private RecyclerView recyclerView;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        this.activity= (MainActivity) context;
    }


    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        if (layoutView==null){
            layoutView=inflater.inflate(R.layout.fragment_house,null);
        }
        tvTitle=layoutView.findViewById(R.id.tv_title);
        tvRight=layoutView.findViewById(R.id.tv_right);
        recyclerView=layoutView.findViewById(R.id.recyclerView);

        recyclerView.setLayoutManager(new LinearLayoutManager(activity,LinearLayoutManager.VERTICAL,false));
        HouseAdapter adapter=new HouseAdapter();
        recyclerView.setAdapter(adapter);
        tvTitle.setText("房源");

        addListener();
        return layoutView;
    }


    private void addListener(){
        tvRight.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.tv_right:
                Intent intent=new Intent(activity,HouseAddActivity.class);
                activity.startActivity(intent);
                break;
            default:
                break;
        }
    }
}
